<?php namespace system\tag;

use hdphp\view\TagBase;

class Tag extends TagBase {
    /**
     * 标签声明
     * @var array
     */
    public $tags
        = [
            'category' => [ 'block' => true, 'level' => 4 ],
            'article'  => [ 'block' => true, 'level' => 4 ],
        ];

    public function _article( $attr, $content ) {
        $row  = isset( $attr['row'] ) ? $attr['row'] : 10;
        $type = isset( $attr['type'] ) ? $attr['type'] : 'new';
        $php
            = <<<str
		<?php 
		\$db = Db::table('plugin_web_article')->limit($row);
		switch('$type'){
			case 'new':
				\$db->orderBy('id','DESC');
				break;
		}
		\$data = \$db->get();
		foreach((array)\$data as \$field):
			\$field['link']=web_url('site/show','web',['id'=>\$field['id']]);
		?>
		$content
str;
        $php .= "<?php endforeach;?>";

        return $php;
    }






}